import pymongo
import redis
import json
import time

# 指定Redis数据库信息
rediscli = redis.StrictRedis(host='localhost', port=6379, db=0)
# 指定MongoDB数据库信息
mongocli = pymongo.MongoClient(host='localhost', port=27017)

# 创建数据库名
db = mongocli['fang']
# 创建表名
newhouse = db['newhouse']
esfhouse = db['esfhouse']

while True:
    source, data = rediscli.blpop(["ftx_spider:items"])

    item = json.loads(data)
    # time.sleep(1)
    if 'title' in item.keys():
        # print(item)

        print('二手房',item)
        esfhouse.insert_one(item)
    else:
        print('新房',item)
        newhouse.insert_one(item)

